<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /**
         * 当不希望一个变量造成全局污染,又常驻内存,就使用闭包
        */
        function create() {
            let a = 100;
            return function () {
                console.log(a);
            }
        }
        /**
         * fn = function(){
         *     console.log(a);
         * }
         * fn是全局变量,他没有调用a的内存就不会被释放掉
        */
        var fn = create();
        fn();       //100
    </script>
</body>
</html>